package com.loanly.controller;

import java.util.List;


import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.classic.*;
//import org.hibernate.Session;
 
import com.loanly.model.Login;

import com.loanly.util.HibernateUtil;
 
public class LoginManager extends HibernateUtil {
 
    public Login add(Login login) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
//        login.setLoginName("121");
        session.save(login);
        session.getTransaction().commit();
        return login;
    }
    public Login delete(Long id) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        Login login = (Login) session.load(Login.class, id);
        if(null != login) {
            session.delete(login);
        }
        session.getTransaction().commit();
        return login;
    }
 
    public List<Login> list() {
         
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List<Login> logins = null;
        try {
             
        	logins = (List<Login>)session.createQuery("from Login").list();
             
        } catch (HibernateException e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }
        session.getTransaction().commit();
        return logins;
    }
}